<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>


    function* sum(num) {
      let a = yield num;
      let b = yield a + num;
      console.log(a + b + num);
    }
    let g = sum(1); // 执行之后返回一个遍历器对象，用于遍历内部的代码

    function wait(time, fn) {
      setTimeout(fn, time);
    }

    function* timeOut() {
      yield (fn) => wait(1000, () => {
        console.log(1)
        fn();
      })
      yield (fn) => wait(1000, () => {
        console.log(2)
        fn()
      })
    }
    let t = timeOut();

    function waitPromise(time) {
      return new Promise((resolve) => {
        setTimeout(resolve, time);
      })
    }

    function* timoutPromise() {
      let r1 = yield waitPromise(1000)
      console.log(r1);
      let r2 = yield waitPromise(1000)
      console.log(r2);
    }

    let tp = timoutPromise();
  </script>
</body>

</html>